With TeselaGen's platform you can close the Design-Build-Test-Learn (DBTL) cycle using machine learning algorithms that automatically learn from your data. The DISCOVER module is capable of suggesting new candidates that can optimize your results given your previous experimental rounds. This document shows how to enable those candidates as new designs at the DESIGN module to perform the next DBTL cycle.
Inputs: Evolutions algorithm's result at an DISCOVER module instance
Outputs: New designs created at DESIGN module
First, we start making all required imports
import platform
from IPython.core.display import display, HTML
import pandas as pd
from teselagen.api import DISCOVERClient, DESIGNClient
from teselagen.utils.candidates_to_design import build_design_from_candidates
print(f"python version : {platform.python_version()}")
print(f"pandas version : {pd.__version__}")
Here, the concept of closing the DBTL loop refers to the ability to generate designs out of what was learned from previous experiments. Those designs can be used to conduct new experimental rounds. This notebook assumes you've already trained an Evolution model.
The results of an Evolution model contain a set of ranked candidates that may outperform your current measurements. Each of the proposed candidates is a combination of the parts (and possibly other variables) you have already tested within the designs in your experiments. These new combinations were evaluated and ranked by a machine learning algorithm and we will generate proper designs with them.
This guide starts at the output of the Evolutions tool at DISCOVER. The next cell connects the notebook with DISCOVER and selects the empty lab (Common
) which holds our sample experiment:
# Connect to your teselagen instance by passing it as the 'host_url' argument of EVOLVECLient(host_url=host_url)
# client = EVOLVEClient(host_url="https://your-instance-name.teselagen.com")
client = DISCOVERClient()
client.login()
client.select_laboratory()
Next, we find the evolutive
model with name Teselagen Example Evolutive Model
:
search_for_name = "Teselagen Example Evolutive Model"
evolution_models_info = client.get_models_by_type('evolutive')
model_id = -1
for info in evolution_models_info:
if info['name'] == search_for_name:
model_id = info['id']
print(f"Model id {info['id']}, name: {info['name']}")
if model_id == -1:
raise IOError("Didn't found model")
And get the models' results. The results objects contain predictions for several untested combinations. We will focus on the rows with valid priority values, which are the better candidates suggested by the algorithm:
results = client.get_model_datapoints(model_id='65', datapoint_type="output", batch_size=400,batch_number=1)
data = pd.DataFrame([el['datapoint'] for el in results['data']])
data = data.dropna(subset=['priority']).reset_index(drop=True)
display(data)
Note the algorithm doesn't suggest candidates you've already tested. That's why the Production
column, the unknown variable for untested combinations in this example, contains only NaN
values.
Now we need to generate a json file with the candidates in order to be imported from DESIGN. We've added an utility for this at the api-client library that is called build_design_from_candidates
. This utility receives a list of dictionaries as input and it requires to explicitly declare the columns that should be interpreted as bins. Following with the example:
design = build_design_from_candidates(
candidates_data = data.to_dict(orient="records"),
bin_cols = ['Teselagen Enzyme A', 'Teselagen Enzyme B'],
name = "Closing DBTL Example",
priority_col='priority'
)
The design
variable contains a dictionary representation of the design. This representation can be easily stored as a json file and then uploaded into DESIGN. To do this, we need to create a DESIGNClient
instance:
design_client = DESIGNClient(host_url = client.host_url)
design_client.select_laboratory()
And upload the design. The method post_design
returns the id of the generated DESIGN in case of success:
response = design_client.post_design(design=design)
display(response)
The new design should be created and look like this:
Uncomment and run the following cell to get the design link:
# design_url = f"{design_client.host_url}/design/client/designs/{response['id']}"
# display(HTML(f"""<a href="{design_url}">{design_url}</a>"""))